home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / netprog.zip / NETPROG.TAR / lib / nspipe.c < prev    next >
C/C++ Source or Header  |  1989-12-17  |  771b  |  32 lines

  1. /*
  2.  * Create a named stream pipe.
  3.  */
  4.  
  5. #include    <sys/types.h>
  6. #include    <sys/socket.h>
  7. #include    <sys/un.h>
  8.  
  9. int            /* returns 0 if all OK, -1 if error (with errno set) */
  10. ns_pipe(name, fd)
  11. char    *name;        /* user-specified name to assign to the stream pipe */
  12. int    fd[2];        /* two file descriptors returned through here */
  13. {
  14.     int            len;
  15.     struct sockaddr_un    unix_addr;
  16.  
  17.     if (s_pipe(fd) < 0)    /* first create an unnamed stream pipe */
  18.         return(-1);
  19.  
  20.     unlink(name);    /* remove the name, if it already exists */
  21.  
  22.     bzero((char *) &unix_addr, sizeof(unix_addr));
  23.     unix_addr.sun_family = AF_UNIX;
  24.     strcpy(unix_addr.sun_path, name);
  25.     len = strlen(unix_addr.sun_path) + sizeof(unix_addr.sun_family);
  26.  
  27.     if (bind(fd[0], (struct sockaddr *) &unix_addr, len) < 0)
  28.         return(-1);
  29.  
  30.     return(0);
  31. }
  32.